home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / NETWORK.SWG / 0006_LOCKREC.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  63 lines

  1. {
  2. The following Program is a slight modification of one posted by Zach
  3. Linnet.  The problem is it doesn't lock the use of the File and allows
  4. multiple PC's to access the File at the same time.  Also, it seems to
  5. take input from the keyboard when it isn't supposed to and I am unable
  6. to locate why.  How could I improve this to actually lock the File?
  7. What if I just wanted to lock one or two Records?
  8. }
  9.  
  10. Program Sample_File_Locking_Program;
  11. Uses
  12.   Crt;
  13. Type
  14.   Fi = File of Integer;
  15. Var
  16.   FileName : String;
  17.   f : Fi;
  18.   x, n : Integer;
  19.   Choice : Char;
  20.  
  21. begin
  22.   {$I-}
  23.   FileName := 'e:\test\test.dat';
  24.   Assign(f,FileName);
  25.   Repeat
  26.     Write('Option [rwq] ? '); choice := ReadKey;
  27.     Writeln(choice);
  28.     Case choice of
  29.       'r' : begin
  30.               Writeln('Attempting to read : ');
  31.               Reset(f);
  32.               While Ioresult <> 0 do
  33.                 begin
  34.                   Writeln('Busy waiting...');
  35.                   Reset(f);
  36.                 end;
  37.               Write('Reading now...');
  38.               For x := 1 to 1000 do
  39.                 Read(f,n);
  40.               Writeln('done!');
  41.               Close(f);
  42.             end;
  43.       'w' : begin
  44.               Writeln('Attempting to Write : ');
  45.               Reset(f);
  46.               if Ioresult = 2 then
  47.                 ReWrite(f);
  48.               While Ioresult <> 0 do
  49.                 begin
  50.                   Writeln('Busy waiting...');
  51.                   Reset(f);
  52.                 end;
  53.               Write('Writing now...');
  54.               For x := 1 to 1000 do
  55.                 Write(f,x);
  56.               Writeln('done!');
  57.               Close(f);
  58.             end;
  59.      end; { Case }
  60.   Until Choice = 'q';
  61.   {$I+}
  62. end.
  63.